﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Resources;
namespace TA.DotNetUtils
{
	public static class ExtensionMIMEMap
	{
		public static string GetMime(string extension)
		{
			return _extensionToMime[extension];
		}
		public static string GetExtension(string mime)
		{
			return _mimeToExtension[mime];
		}

		static Dictionary<string, string> _extensionToMime = new Dictionary<string, string>(),
			_mimeToExtension = new Dictionary<string, string>();
		static void AddMapping(string extension, string mime)
		{
			_extensionToMime[extension] = mime;
			_mimeToExtension[mime] = extension;
		}
		static ExtensionMIMEMap()
		{
			using (TextReader tr = new StringReader(TA.DotNetUtils.Other.ExtensionsMIMEs.Mappings))
			{
				string line;
				while (!string.IsNullOrEmpty(line = tr.ReadLine()))
				{
					string[] parts = line.Split('|');
					AddMapping(parts[0], parts[1]);
				}
			}
		}
	}
}
